﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using SFGX.Mango.Configuration;
using SFGX.Mango.Web;

namespace SFGX.Mango.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class MangoDbContextFactory : IDesignTimeDbContextFactory<MangoDbContext>
    {
        public MangoDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<MangoDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            MangoDbContextConfigurer.Configure(builder, configuration.GetConnectionString(MangoConsts.ConnectionStringName));

            return new MangoDbContext(builder.Options);
        }
    }
}
